package com.yaozheng.vocationaltraining.view;

import net.sf.json.JSONObject;

import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

import com.yaozheng.vocationaltraining.R;
import com.yaozheng.vocationaltraining.utils.BitmapLoader;
import com.yaozheng.vocationaltraining.utils.TypeUtils;

import android.content.Context;
import android.graphics.Color;
import android.text.Html;
import android.util.AttributeSet;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * 课程目录一项view
 *
 * @author Administrator
 */
@EViewGroup(R.layout.item_course_catalog)
public class CourseCatalogItemView extends LinearLayout {
    @ViewById
    TextView coursewareTitleText;
    @ViewById
    ImageView coursewareImage;

    @ViewById
    ExamProgressStatusView examProgressStatusView;


    public CourseCatalogItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
    }

    public CourseCatalogItemView(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    }

    public void loadData(int position, JSONObject courseJsonObject,
                         BitmapLoader bitmapLoader) {
        coursewareTitleText.setText(TypeUtils.getJsonString(courseJsonObject,
                "subject"));

        if (TypeUtils.getJsonBoolean(courseJsonObject, "learned")) {
            //复习
        } else {
//            学习
        }
        examProgressStatusView.getExamProgressButtonStatusView().setInnerCirclePaintColor(Color.parseColor("#3Fe5e5e5"));
        examProgressStatusView.setPaperStatusTypeExplanationTextValue("%");
        examProgressStatusView.setStatus(TypeUtils.getJsonInteger(courseJsonObject, "learned_percent", 0));
        examProgressStatusView.setTextColorWhite();
        loadCoursewareImage(courseJsonObject, bitmapLoader);
    }

    /**
     * 加载图片
     *
     * @param courseJsonObject
     */
    public void loadCoursewareImage(JSONObject courseJsonObject,
                                    BitmapLoader bitmapLoader) {
        bitmapLoader.displayImage(
                TypeUtils.getJsonString(courseJsonObject, "image"),
                coursewareImage);
    }
}
